package BianyTest1;

import java.util.Scanner;

public class ScannerTest {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int[] arr = new int[5];

        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第" + (i+1) + "个数字");
            arr[i] = scanner.nextInt();
        }

        System.out.print("您输入的数据为：");

        for (int j : arr) {
            System.out.print(j + "\t");
        }
        System.out.println();

        Reversal reversal =new Reversal();
        reversal.reversal(arr);
        System.out.print("排序后的数据为：");
        for (int i : arr) {
            System.out.print(i + "\t");
        }


    }

    public static class Reversal{
        public void reversal(int[] arr){
            for (int i = 0; i < arr.length-1; i++) {
                for (int j = 0; j < arr.length-1-i; j++) {
                    if (arr[j] > arr[j+1]){
                        int temp = arr[j];
                        arr[j] = arr[j+1];
                        arr[j+1] = temp;
                    }
                }
            }
        }

    }
}
